package stjdb;
import java.util.Scanner;
import java.util.Random;
public class shi {

        /*
         *@ClassName ${NAME}华为软工2102
         *@Author szw
         *@ Description 石头剪刀布
         *@date ${DATE} ${TIME}2022/3/25 19：30
         *@Version 1.0
         */

        public static void main(String[] args)
        {
            System.out.println("     程序已启动     ");
            System.out.println("猜拳游戏开始" + "\n" + "请输入数字 1 :剪刀 2 :石头 3 :布");
            String user = "用户";
            String comp = "电脑";
            int userScore=0;//定义用户分数
            int compScore=0;//定义电脑分数
            for(int i=1;i<=5;i++)//使用for循环定义局数
            {
                System.out.println("\n"+"第"+i+"局游戏开始"+"\n");
                Scanner s = new Scanner(System.in);//获取用户键盘输入信息
                int person = s.nextInt();
                int computer=new Random().nextInt(4);//获取电脑随机数

                switch (person)
                {
                    case 1:
                        user = "剪刀";
                        System.out.println("剪刀");
                        break;
                    case 2:
                        user = "石头";
                        System.out.println("石头");
                        break;
                    case 3:
                        user = "布";
                        System.out.println("布");
                        break;
                }
                switch (computer)
                {
                    case 1:
                        comp = "剪刀";
                        System.out.println("电脑本次出的是剪刀");
                        break;
                    case 2:
                        comp = "石头";
                        System.out.println("电脑本次出的是石头");
                        break;
                    case 3:
                        comp = "布";
                        System.out.println("电脑本次出的是布");
                        break;
                }

                if (person == 1 && computer == 2 || person == 2 && computer == 3 || person == 3 && computer == 1)//输的情况
                {
                    System.out.println("你输了");
                    compScore++;
                }
                else if (person == computer)
                {
                    System.out.println("打平了");
                }
                else
                {
                    System.out.println("你赢了");
                    userScore++;
                }
                if(userScore == 3)//五局三胜，用户分数为3时提前结束游戏
                    break;
            }

            System.out.print("\n");

            if(userScore>compScore)
            {
                System.out.println("最终结果是你赢了" + "\n" + "本次游戏你赢了" + userScore + "局" + "\n" + "输了" + compScore + "局");
            }
            if(userScore<compScore)
            {
                System.out.println("最终结果是你输了" + "\n" + "本次游戏你赢了" + userScore + "局" + "\n" + "输了" + compScore + "局");
            }
            if(userScore==compScore)
            {
                System.out.println("和局！" + "\n" + "本次游戏你赢了" + userScore + "局" + "\n" + "输了" + compScore + "局");
            }
        }
    }



